package com.thousandsunny.nosql;

import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

import java.net.MalformedURLException;

@SpringBootApplication
@Component
public class NoSqlApplication {
    public static void main(String[] args) {
        SpringApplication.run(NoSqlApplication.class, args);
    }

    @Value("${spring.redis.host}")
    private String address;
    @Value("${spring.redis.password}")
    private String password;
    @Value("${spring.redis.port}")
    private String port;

    @Bean
    public RedissonClient redisson() throws MalformedURLException {
        Config config = new Config();
        String uri = "redis://" + address.trim() + ":" + port.trim();
        config.useSingleServer()
                .setAddress(uri)
//        config.useClusterServers() //这是用的集群server
                .setPassword(password);
//                .setScanInterval(2000) //设置集群状态扫描时间
//                .setMasterConnectionPoolSize(10000) //设置连接数
//                .setSlaveConnectionPoolSize(10000)
//                .addNodeAddress(uri);
        return Redisson.create(config);
    }
}
